package com.qlzb.taskmanagement.utils;

import java.text.SimpleDateFormat;
import java.util.*;

public class StringUtils {
    /**
     * 获得一个UUID
     * @return String UUID
     */
    public static String getUUID(){
        String s = UUID.randomUUID().toString();
        //去掉“-”符号
        return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
    }
    public static int  random(int min,int max){
       int random= new Random().nextInt(max-min)+min;
       return random;
    }

    /**
     * 请求参数转换
     * @param value
     * @return
     */
    public static Map paramsTransformation(String value){
        /*try {
            value = URLDecoder.decode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }*/
        Map<String,String> params = new HashMap<>();
        String[] paramsList = value.split("&");
        for (String paraStr : paramsList) {
            String[] str = paraStr.split("=");
            if (str.length==1){
                params.put(str[0].trim(),"");
            }else if (str.length == 2){
                params.put(str[0],str[1]);
            }
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (params.size() == paramsList.length){
            System.out.println(df.format(new Date())+" 对象转换成功");
        }
        return params;
    }
}
